package com.ubst.smartad.tree;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import com.ubst.smartad.logger.Debug;

public class TreeMngImpl {
	Connection con = null;
	private String serverName;
	private Debug debug;
	//private FileHostEnv fhostEnv;
	
	/** 
     * 생성자
     *   
     *   
    */ 
	public TreeMngImpl(Connection con, String serverName, String log_level) {
		this.con = con;
		this.serverName = serverName;
		this.debug = new Debug("TestMngImpl", log_level);
		//this.fhostEnv = FileHostEnv.getInstance(serverName);
	}
	
	/**
	 *  @author Kswany
	 * 	Log jqGrid List 가져오기
	 * 
	 *  searchStr: 검색조건
	 *  orderBy: sort조건
	 *  prev_page: first limit 
	 *  next_page: last limit
	 *  
	 * **/
	
	public List<HashMap<String,String>> makeTempData() {
		List<HashMap<String,String>> dataList = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> treeData = new HashMap<String,String>();
		treeData.put("code", "00");
		treeData.put("name", "전체");
		treeData.put("class", "folder");
		treeData.put("p_code", "-1");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "01");
		treeData.put("name", "내부");
		treeData.put("class", "folder");
		treeData.put("p_code", "00");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0101");
		treeData.put("name", "서버");
		treeData.put("class", "folder");
		treeData.put("p_code", "01");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010101");
		treeData.put("name", "Linux Agent");
		treeData.put("class", "file");
		treeData.put("p_code", "0101");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010102");
		treeData.put("name", "Unix Agent");
		treeData.put("class", "file");
		treeData.put("p_code", "0101");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0102");
		treeData.put("name", "윈도우");
		treeData.put("class", "folder");
		treeData.put("p_code", "01");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010201");
		treeData.put("name", "Win Agent1");
		treeData.put("class", "file");
		treeData.put("p_code", "0102");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010202");
		treeData.put("name", "Win Agent2");
		treeData.put("class", "file");
		treeData.put("p_code", "0102");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0103");
		treeData.put("name", "DB");
		treeData.put("class", "folder");
		treeData.put("p_code", "01");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010301");
		treeData.put("name", "Oracle");
		treeData.put("class", "file");
		treeData.put("p_code", "0103");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "010302");
		treeData.put("name", "Mysql");
		treeData.put("class", "file");
		treeData.put("p_code", "0103");
		dataList.add(treeData);
		
		treeData = new HashMap<String,String>();
		treeData.put("code", "02");
		treeData.put("name", "내부");
		treeData.put("class", "folder");
		treeData.put("p_code", "00");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0201");
		treeData.put("name", "서버");
		treeData.put("class", "folder");
		treeData.put("p_code", "02");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020101");
		treeData.put("name", "Linux Agent");
		treeData.put("class", "file");
		treeData.put("p_code", "0201");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020102");
		treeData.put("name", "Unix Agent");
		treeData.put("class", "file");
		treeData.put("p_code", "0201");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0202");
		treeData.put("name", "윈도우");
		treeData.put("class", "folder");
		treeData.put("p_code", "02");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020201");
		treeData.put("name", "Win Agent1");
		treeData.put("class", "file");
		treeData.put("p_code", "0202");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020202");
		treeData.put("name", "Win Agent2");
		treeData.put("class", "file");
		treeData.put("p_code", "0202");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "0203");
		treeData.put("name", "DB");
		treeData.put("class", "folder");
		treeData.put("p_code", "02");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020301");
		treeData.put("name", "Oracle");
		treeData.put("class", "file");
		treeData.put("p_code", "0203");
		dataList.add(treeData);
		treeData = new HashMap<String,String>();
		treeData.put("code", "020302");
		treeData.put("name", "Mysql");
		treeData.put("class", "file");
		treeData.put("p_code", "0203");
		dataList.add(treeData);
		
		return dataList;
	}
	
	/*
	 * searchType 
	 *  - 0 : 시스템명
	 *  - 1 : IP주소
	 */
	public List<HashMap<String,String>> getSystemTree(String searchStr, int searchType) throws Exception{
		//PreparedStatement pstmt = null;
		//ResultSet rs = null;
		List<HashMap<String,String>> dataList = null;
				
		try{
		/*
		 *  DB value 값세팅 구현 로직 들어갈 부분
		 */
		// 가상데이터
			dataList = makeTempData();
		}catch (Exception e){
			throw e;
		}finally{
	//		if ( rs != null) try{rs.close();}catch(SQLException ee){}
	//		if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
	
		return dataList;
	}
}
